namespace Homework {
    class Product {
        constructor(private _name: string, private _price: number, private _quantity: number) {
            this._name = _name;
            this._price = _price;
            this._quantity = _quantity;
        }

        get name(): string {
            return this._name;
        }

        set name(value: string) {
            this._name = value;
        }

        get price(): number {
            return this._price;
        }

        set price(value: number) {
            this._price = value;
        }

        get quantity(): number {
            return this._quantity;
        }

        set quantity(value: number) {
            this._quantity = value;
        }

        private calculateTotalPrice() {
            return this._price * this._quantity;
        }

        getDescription = (): string => `${this._name} - $${this._price} x ${this._quantity}=$${this.calculateTotalPrice()}`

    }

    class ShoppingCart {
        static cartCount = 0;
        private products: Product[];

        constructor() {
            this.products = [];
            ShoppingCart.cartCount++;
        }

        // 静态方法返回购物车总数
        static getCartCount() {
            return ShoppingCart.cartCount;
        }

        // 添加商品
        addProduct(product: Product) {
            this.products.push(product);
        }

        // 移除商品
        removeProduct(productName: string) {
            this.products = this.products.filter(product => product.name !== productName);
        }

        // 计算购物车总价
        calculateTotalPrice() {
            return this.products.reduce((total, product) => total + product.price * product.quantity, 0);
        }

        // 获取购物车商品列表
        getProducts() {
            return this.products;
        }

        // 设置购物车商品列表
        setProducts(products: Product[]) {
            this.products = products;
        }
    }


    let product1 = new Product("iPhone", 699, 2);
    console.log(product1.getDescription());

}
